package com.szsfm.vehiclemanagement.mvp.model.modelImpl;

import com.orhanobut.logger.Logger;
import com.szsfm.vehiclemanagement.bean.Message;
import com.szsfm.vehiclemanagement.bean.PushMessage;
import com.szsfm.vehiclemanagement.manager.GreenDaoManager;
import com.szsfm.vehiclemanagement.mvp.model.IMessageModel;
import com.szsfm.vehiclemanagement.tcp.TcpCore;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhoubigbo on 2017/11/29.
 */

public class MessageModelImpl implements IMessageModel {

    @Override
    public void receiveMessages() {

    }

    @Override
    public void requestMessages(MessageCallback callback) {
        Logger.d("开始请求数据");
        List<Message> messages = new ArrayList<>();
        messages.add(new Message("车牌号","粤AJ5647"));
        messages.add(new Message("违章时间","2016-11-24 12:14:56 \n2016-11-25 12:14:56 \n2016-11-26 12:14:56"));
        messages.add(new Message("违章地点","金地一路"));
        messages.add(new Message("违章次数","3"));
        callback.messages(messages);
        List<PushMessage> msgs = GreenDaoManager.getInstance().getPushMessageDao().queryBuilder().list();
        List<Long> ids = new ArrayList<>();
        for (PushMessage pMsg:msgs){
            Logger.d("msg->"+pMsg.toString());
            for (Message msg:pMsg.getData()){
                ids.add(msg.getMsgId());
                msg.setRead(true);
            }
            GreenDaoManager.getInstance().getPushMessageDao().update(pMsg);
        }

        if (ids.size()>0)
            TcpCore.updateMessageRead(ids);
    }
}
